home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / NibEditor / combine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-12  |  1.2 KB  |  79 lines

  1. /*
  2.  * combine.c:
  3.  *
  4.  * This program will take a NIBLIST and a set of NIBS in your directory
  5.  * and a program and recombine them into a new program...
  6.  */
  7.  
  8. #include <libc.h>
  9. FILE    *nibfile;
  10. char    **niblist;
  11. int    nibs=0;
  12. char    *inprog;
  13. char    *outprog;
  14. char    tempprog[256];
  15.  
  16. void    usage()
  17. {
  18.     printf("usage: extract <input-program> <output-program>\n");
  19.     exit(1);
  20. }
  21.  
  22.  
  23. int    insert_nib(char *nibname,char *filename)
  24. {
  25.     char    buf[256];
  26.  
  27.     sprintf(buf,"/bin/segedit -replace __NIB %s %s %s -output %s",
  28.         nibname,filename,outprog,tempprog);
  29.  
  30.     puts(buf);
  31.     system(buf);
  32.  
  33.     sprintf(buf,"/bin/mv %s %s",tempprog,outprog);
  34.     system(buf);
  35.     printf("\t%s\n",buf);
  36. }
  37.  
  38.  
  39.  
  40. int    main(int argc,char **argv)
  41. {
  42.     char    buf[256];
  43.  
  44.     if(argc<3){
  45.         usage();
  46.     }
  47.  
  48.     inprog    = argv[1];
  49.     outprog    = argv[2];
  50.  
  51.     sprintf(tempprog,"%s.new",outprog);
  52.     sprintf(buf,"/bin/cp %s %s",inprog,outprog);
  53.     system(buf);
  54.  
  55.     /* process NIBLIST */
  56.  
  57.     nibfile    = fopen("NIBLIST","r");
  58.     if(!nibfile){
  59.         perror("NIBLIST");
  60.         exit(1);
  61.     }
  62.  
  63.     while(!feof(nibfile)){
  64.         char    nibname[256];
  65.         char    filename[256];
  66.         long    mtime;
  67.         
  68.         if(fscanf(nibfile,"%s %s %ld",nibname,filename,&mtime)==3){
  69.             struct stat sbuf;
  70.  
  71.             stat(filename,&sbuf);
  72.             if(mtime!=sbuf.st_mtime){
  73.                 insert_nib(nibname,filename);
  74.             }
  75.         }
  76.     }
  77.     return(0);
  78. }
  79.